﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using nvn.Core.MVP;
using Hutech.CRM.Library.Views;
using Hutech.CRM.Library.Models.BusinessAccessLayer;
using Hutech.CRM.Library.Models.BusinessAccessLayer.BusinessObjects;
using Hutech.CRM.Library.Models.Entities;
using nvn.Library.Patterns;
using Hutech.CRM.Library.Utilities;

namespace Hutech.CRM.Library.Presenters
{
    public class AddAndViewCustomerPresenterFull : BasePresenter<IAddAndViewCustomerFullView>
    {
        
        #region First Description
        public AddAndViewCustomerPresenterFull(IAddAndViewCustomerFullView view)
            : base(view)
        {
            this.view.FristLoadEventHandler += new EventHandler<EventArgs>(view_FristLoadEventHandler);
            this.view.Save_Click += new EventHandler<SaveEventAgrs<AccountCustomer>>(view_Save_Click);
            this.view.Cancel_Click += new EventHandler<EventArgs>(view_Cancel_Click);
        }
        #endregion

        #region All Event
        void view_FristLoadEventHandler(object sender, EventArgs e)
        {
            view.Jobs = LoadGroupCategories(ConstantVariable.CATEGORY_JOB);
            view.Positions=LoadGroupCategories(ConstantVariable.CATEGORY_POSITION);
            view.ProvinceOrCities=LoadGroupCategories(ConstantVariable.CATEGORY_PROVINCEORCITY);
        }

        void view_Cancel_Click(object sender, EventArgs e)
        {
        }

        void view_Save_Click(object sender, SaveEventAgrs<AccountCustomer> e)
        {
            IAccountCustomerBAL itemBAL = new AccountCustomerBAL();

            AccountCustomer item = e.myType;
            item.IsDelete = false;
            item.LastUpdatedDate = DateTime.Now;
            item.Level = ConstantVariable.VALUE_LEVEL_1;
            //se them ham kiem tra level dau tien cho nay

            if (itemBAL.Save(item))
            {
            }
            else
            {
            }
        }
        #endregion

        #region private method
        List<TowTypeParameters<Guid, string>> LoadGroupCategories(Guid itemGuid)
        {
            IAllCategoriesBAL itemBAL = new AllCategoriesBAL();
            return itemBAL.GetAllItemOfGroupCategoryForDropDownList(itemGuid,ConstantVariable.VALUE_DEFAULT_STRING_DROPDOWNLIST);
        }
        //void RefreshAllControl() 
        //{
        //    view.GroupLevelCustomers = LoadGroupLevelCustomer();
        //    view.CriterionName = string.Empty;
        //}
        #endregion
    }
}
